package ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.persistence.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.persistence.UserDAO;
import ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.persistence.model.Device;
import ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.persistence.model.SimpleUser;
import ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.persistence.model.User;

public class UserDAOImpl extends HibernateDaoSupport implements UserDAO{

	@Override
	public User findByUsername(String username) {
		return (User)getHibernateTemplate().get(User.class, username);		
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Device> getDevices(User userlogged) {
		String id_user = userlogged.getUserName();
		String query = "select D.* from Device D, User_Device UD"
						+" where D.id= UD.device AND UD.user = ?";
		return (List<Device>)getHibernateTemplate().find(query, id_user);				
	}


	@Override
	public void saveOrUpdateUser(SimpleUser user) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void deleteUser(SimpleUser user) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public List<SimpleUser> listUsers() {
		// TODO Auto-generated method stub
		return null;
	}

}
